/*
  This file is part of 'Trivial chess'.

  'Trivial chess' is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  'Trivial chess' is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with 'Trivial chess'.  If not, see <http://www.gnu.org/licenses/>.
*/

/* SVN FILE: $Id$ */
/**
 * @author         $Author$
 * @version        $Rev$
 * @lastrevision   $Date$
 * @filesource     $URL$
 */

#ifndef PIECESHIFT_H_
#define PIECESHIFT_H_

#include <boost/cstdint.hpp>

#include "PieceAbstract.h"

template<typename Int = int8_t>
class PieceShift : public PieceAbstract<ShiftPiece, Int> {
public:
	static const PieceShift<Int> PAWN()   { return PieceShift<Int>(0); }
	static const PieceShift<Int> BISHOP() { return PieceShift<Int>(2); }
	static const PieceShift<Int> KNIGHT() { return PieceShift<Int>(4); }
	static const PieceShift<Int> ROOK()   { return PieceShift<Int>(6); }
	static const PieceShift<Int> QUEEN()  { return PieceShift<Int>(8); }
	static const PieceShift<Int> KING()   { return PieceShift<Int>(10); }

	static const PieceShift<Int> NIL()  { return PieceShift<Int>(12); }
	static const PieceShift<Int> END()  { return PieceShift<Int>::NIL(); }
	static const PieceShift<Int> REND() { return PieceShift<Int>(-2); }
public:
	PieceShift() {}

	explicit PieceShift(const Int piece) : piece(piece)  {}
	explicit PieceShift<Int>(const std::string str)  { this->me().fromStr(str); }

	Int toInt() const {
		return this->piece >> 1;
	}

	void fromInt(const Int piece) {
		this->piece = piece << 1;
	}

	PieceShift<Int> operator++() {
		return PieceShift<Int>(this->piece+=2);
	}

	PieceShift<Int> operator--() {
		return PieceShift<Int>(this->piece-=2);
	}

	bool operator==(const PieceShift<Int> piece) const {
		return this->piece == piece.piece;
	}

private:
	Int piece;

};



#endif /* PIECESHIFT_H_ */
